#pragma once

enum EConnectionStatus
{
    eConnectionStatus_Disconnected,
    eConnectionStatus_Connected,
    eConnectionStatus_Pending,
    eConnectionStatus_Error
};


class CBaseConnection
{

public:
    CBaseConnection();

    bool Connect(const char* szServerName, WORD wPort);
    void Update();
   
    EConnectionStatus GetConnectionStatus() const { return m_eConnectionStatus; }
    WORD GetPort() { return m_wPort; }

    void WriteData(BYTE* pbData, int cbLen);

    BYTE* GetReadBufferHead() { return m_rgReadBuffer; }
    int GetCBBufferedRead() { return m_cbBufferedRead; }
    void ConsumeReadBuffer(int cbConsume);
private:

    void Initialize();

    int m_socket;

    static const int m_cchServerNameMax = 160;
    char m_szServerName[m_cchServerNameMax];
    short m_wPort;
    static bool m_sNetworkInitialized;

    EConnectionStatus m_eConnectionStatus;

    static const int m_cbMaxWriteBuffer = 32*1024;
    static const int m_cbMaxReadBuffer = 32*1024;

    BYTE m_rgWriteBuffer[m_cbMaxWriteBuffer];
    BYTE m_rgReadBuffer[m_cbMaxReadBuffer];

    int m_cbBufferedRead;
    int m_cbBufferedWrite;
};

